/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
/-storage ...
/-storage/attached ...
/-storage/attached/api
/-storage/attached/dom ...
DetectStorage.ts
LoadStorage.ts
UpdateStorage.ts
/-storage/attached/indexedDB
/-storage/attached/localStorage
/-storage/attached/webSQL
/-tests
/-typings
TypeScriptService.ts
functions.ts
ko.ts
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.js
teapo.ts
x
1
module teapo.storage.attached.dom {
2
3
  export class LoadStorage implements attached.LoadStorage {
4
5
    editedUTC: number;
6
7
    private _byName: { [fullPath: string]: HTMLElement; } = {};
8
9
    constructor(
10
      private _parentElement: HTMLElement,
11
      private _document: { createElement(tag: string): HTMLElement; }) {
12
13
      // populate editedUTC from corresponding attribute
14
      var editedUTCValue = this._parentElement.getAttribute('data-edited-utc');
15
      if (editedUTCValue) {
16
        try {
17
          this.editedUTC = parseInt(editedUTCValue);
18
        }
19
        catch (parseEditedUTCError) {
20
          console.log('parsing editedUTC ' + parseEditedUTCError);
21
        }
22
      }
23
    }
24
25
    load(recipient: LoadStorageRecipient): void {
26
      //alert('load() editedUTC: ' + this.editedUTC+'\n' + this._parentElement.outerHTML);
27
      this._loadFromElement(this._parentElement, recipient);
28
      var updater = new UpdateStorage(this._parentElement, this._byName, this._document);
29
      recipient.completed(updater);
30
    }
31
32
    migrate(
33
      editedUTC: number,
34
      filesByName: { [fullPath: string]: { [propertyName: string]: string; }; },
35
      callback: (error: Error, updater: attached.UpdateStorage) => void): void {
36
37
      this._wipeExistingElement();
38
      if (editedUTC)
39
        this._parentElement.setAttribute('data-edited-utc', editedUTC + '');
40
      this.editedUTC = editedUTC;
41
      //alert('migrate(' + editedUTC + ', ' + JSON.stringify(filesByName) + ')\n' + this._parentElement.outerHTML);
42
43
44
      if (filesByName) {
45
        for (var fullPath in filesByName) if (filesByName.hasOwnProperty(fullPath)) {
46
          var element = UpdateStorage.createElement(this._parentElement, fullPath, this._document);
47
          this._byName[fullPath] = element;
48
        }
49
      }
50
51
      var updater = new UpdateStorage(this._parentElement, this._byName, this._document);
52
53
      callback(null, updater);
54
    }
55
56
    private _wipeExistingElement() {
57
      // clear out the attributes
25:8